package org.dmikis.jmmengine.viewes;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import org.dmikis.jmmengine.models.Model;

/**
 * @author dmikis
 * @version 0.1
 * 
 * Class extends <code>JDialog</code> for working with <code>Model</code>.
 */
@SuppressWarnings("serial")
public class ParametersDialog extends JDialog {
    
    /**
     * Create new dialog and fill it by model's parameters panel and OK and Cancel buttons.
     * 
     * @param m model to work with
     */
    public ParametersDialog(Model m) {
	super();
	setModal(true);
	setResizable(false);
	setTitle("Parameters");
	this.model = m;
	add(this.model.getParametersPanel(), BorderLayout.CENTER);
	JPanel buttonPanel = new JPanel();
	JButton buttonOk = new JButton("OK");
	buttonOk.addActionListener(new ActionListener() {

	    @Override
	    public void actionPerformed(ActionEvent a) {
		try {
		    model.renewModelParameters();
		    setVisible(false);
		}
		catch (Exception e) {
		    System.err.println(e.getMessage());
		}
	    }
	});
	buttonPanel.add(buttonOk);
	JButton buttonCancel = new JButton("Cancel");
	buttonCancel.addActionListener(new ActionListener() {

	    @Override
	    public void actionPerformed(ActionEvent arg0) {
		setVisible(false);
	    }
	});
	buttonPanel.add(buttonCancel);
	add(buttonPanel, BorderLayout.SOUTH);
	pack();
    }

    private Model model;
}
